package cn.imvc.app.repositories;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import cn.imvc.app.entities.Goods;
import cn.imvc.app.entities.GoodsPrice;
import cn.imvc.app.entities.GoodsSku;
import cn.imvc.data.jpa.repository.IJpqlExecutor;

public interface GoodsPriceRepository extends JpaRepository<GoodsPrice, Integer>,IJpqlExecutor<GoodsPrice>{
	public void deleteByGoods(Goods goods);
	public void deleteByGoodsSku(GoodsSku goodsSku);
	
	@Query("select max(g.price) as price from GoodsPrice g where g.goods.id = :id and g.goodsSku.state<>0 group by g.goodsSku order by price asc")
	List<Integer> getLowPriceByClass(@Param("id")int id);
	
	@Query("select g from GoodsPrice g where g.goods.id = :id order by g.goodsSku,g.priceClass.sort asc")
	List<GoodsPrice> getGoodsPrices(@Param("id")int id);
	
	@Query("select min(g.price) as price from GoodsPrice g where g.goods.id = :id and g.goodsSku.state<>0 and g.priceClass.code='member' group by g.goodsSku order by price asc")
	List<Integer> getLowMemberPrice(@Param("id")int id);
}
